<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/10/22
  Time: 19:46
 注册页面
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="inspur.dao.UserDao,inspur.common.FiledCheck,inspur.entity.User" %>
<%@ include file="config.jsp"%>
<html>
<head>
    <title><%=webTitle%></title>
    <meta name="Keywords" content="<%=keywords%>">
    <meta name="Description" content="<%=Description%>">
    <link rel="stylesheet" href="css/style.css">
    <script>
        var issuccess=false;
        if (issuccess){
            alert("注册成功，3秒后跳转到登录界面");
            setTimeout(window.open("login.jsp"),3000);
        }
    </script>
</head>
<body>
    <div align="center">
        <%@include file="component/top.jsp"%><!---顶栏-->
        <%@include file="component/checkBox.jsp"%><!--搜索框-->
        <table>
            <tr>
                <td>
                    <%
                        boolean isSuccess=false;
                        String userIdError="";
                        String passWordError="";
                        String userNameError="";
                        String secondPassError="";
                        //从表单里面获得用户名和密码的值
                        request.setCharacterEncoding("utf-8");
                        //String username=request.getParameter("UserId");
                        String userId=request.getParameter("userId");
                        String passWord=request.getParameter("passWord");
                        String secondPass=request.getParameter("secondPass");
                        String userName=request.getParameter("userName");
                        if (userId==null){
                            userId="";
                        }
                        if (passWord==null){
                            passWord="";
                        }if (secondPass==null){
                            secondPass="";
                    }
                    if (userName==null){
                            userName="";
                    }


                        //非空的校验
                        if(FiledCheck.isBlack(userId)){


                        }else if(FiledCheck.isBlack(passWord)){


                        }else if(!passWord.equals(secondPass)){

                        }else {



                            //登录信息的校验
                            User user=new User();
                            user.setId(userId);
                            user.setUsername(userName);
                            user.setPassword(passWord);



                            UserDao userDao=new UserDao();
                            int num=userDao.reg(user);
                            if(num==2){
                                userNameError="注册成功,2秒后跳转到登录界面";
                                isSuccess=true;
                            }else{
                                //用户名 或者密码错误
                                if(num==0){
                                    userNameError="用户已存在";
                                }else{
                                    //用户名不存在 或者 错误
                                    //request.setAttribute("usernameError", "用户名错误");

                                }
                                //请求转发
                                //request.getRequestDispatcher("/login.jsp").forward(request, response);
                                System.out.println("hello ");

                            }

                        }







                    %>
                    <script>
                        issuccess=<%=isSuccess%>;
                        if (issuccess){
                            setTimeout("self.location='login.jsp';",2000);


                        }
                    </script>
                    <form method='post' action='' >
                        <p align="left" >

                            用户账号：<input type=text class="box2" name="userId" value='<%=userId%>'><%=userIdError%><br><br>
                            账号密码：<input type=password class="box2" name="passWord" value='<%=passWord%>'><%=passWordError%><br><br>
                            重复密码：<input type=password class="box2" name="secondPass" value='<%=secondPass%>'><%=secondPassError%><br><br>
                            账号昵称：<input type=text class="box2" name="userName" value='<%=userName%>'><%=userNameError%><br><br>
                            <input type="submit" class="bt500x50" name='tj' value='确认无误，提交以上信息' >
                        </P>
                    </form>
                </td>
            </tr>
        </table>
    </div>
    <%

    %>
</body>
    </div>
</body>
</html>
